<script src="https://cdn.bootcdn.net/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
    // type,url,data  可传可不传，也不用考虑顺序

    // function getajax(type="get",url="./data/1.json",data={}) {

    function getajax(  {type,data,url} ={} ) {

        return  new Promise((resolve, reject) => {
            $.ajax({
                type,
                url,
                data,
                success(res) {
                    resolve([null, res])
                },
                error(err) {
                    resolve([err, undefined])
                }
            })
        })

        // return p1
    }



    // 拿取一级城市结果
    async function getcity() {

        let [err, res] = await getajax("get","./data/1.json");

        if (err) {
            alert("出错了")
            return
        }

        let id = res[0].id
        console.log(id);


        // 二级城市
        // let [err1,res1]=await getajax("get");
        // let [err1,res1]=await getajax("get","./data/2.json");
        // let [err1,res1]=await getajax("get",,{id});//出错，不能空着位置

        let [err1,res1]=await getajax(  );
        // let [err1,res1]=await getajax({ type:"get"  } );
        // let [err1,res1]=await getajax({ type:"get",url:"./data/3.json"  } );
        // let [err1,res1]=await getajax({url:"./data/3.json" , type:"get" } );

        console.log(err1, res1);

    }
    getcity()


    
	//分析
    // let {type:type}=
    
    // let {type:type}={ type:"get"  }

    // let  {type:type,data:data} ={ type:"get",data:{id}  }


    // let  {type:type,data:data,url:url}={ type:"get",data:{id}  }

    // let  {type,data,url}={ type:"get",data:{id}  }








</script>

<script src="https://cdn.bootcdn.net/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
